/**
 * 
 */
package server.container;


import java.util.ArrayList;
import java.util.List;

/**
 * @author Christian
 * 
 */
public class SMSAlamierung implements Comparable<SMSAlamierung> {
	
	private String nummer = null;
	
	private EinsatzAlarm alarm = null;
	
	private boolean isUsed;
	
	private boolean korrektGesendet;
	
	private List<String> errorList;
	
	private long lastError = 0;
	
	private String smsmode;
	
	private String userid = "";
	
	private String absender = "";
	
	private String kontostand = "";
	
	private SMSAlamierung() {

		isUsed = false;
		nummer = "";
		korrektGesendet = false;
		errorList = new ArrayList<String>();
	}
	
	public SMSAlamierung(String userid, String nummer, EinsatzAlarm alarm, String smsmode, String absender, String kontostand) {

		this();
		this.userid = userid;
		this.smsmode = smsmode;
		this.nummer = nummer;
		this.alarm = alarm;
		this.absender = absender;
		this.kontostand = kontostand;
	}
	
	public List<String> getErrors() {

		return errorList;
	}
	
	public void addError(String err) {

		setLastError(System.currentTimeMillis());
		errorList.add(err);
	}
	
	/**
	 * @return the isUsed
	 */
	public boolean isUsed() {

		return isUsed;
	}
	
	/**
	 * @param isUsed
	 *            the isUsed to set
	 */
	public void setUsed(boolean isUsed) {

		this.isUsed = isUsed;
	}
	
	/**
	 * @return the nummer
	 */
	public String getNummer() {

		return nummer;
	}
	
	/**
	 * @param nummer
	 *            the nummer to set
	 */
	public void setNummer(String nummer) {

		this.nummer = nummer;
	}
	
	/**
	 * @return the alarm
	 */
	public EinsatzAlarm getAlarm() {

		return alarm;
	}
	
	/**
	 * @param alarm
	 *            the alarm to set
	 */
	public void setAlarm(EinsatzAlarm alarm) {

		this.alarm = alarm;
	}
	
	@Override
	public String toString() {

		StringBuilder builder = new StringBuilder();
		builder.append("Nummer: ");
		builder.append(nummer);
		builder.append("  ");
		builder.append(alarm.toString());
		builder.append(" KontoStand: ");
		builder.append(kontostand);
		return builder.toString();
	}
	
	/**
	 * @return the korrektGesendet
	 */
	public boolean isKorrektGesendet() {

		return korrektGesendet;
	}
	
	/**
	 * @param korrektGesendet
	 *            the korrektGesendet to set
	 */
	public void setKorrektGesendet(boolean korrektGesendet) {

		this.korrektGesendet = korrektGesendet;
	}
	
	/**
	 * @return the lastError
	 */
	public long getLastError() {

		return lastError;
	}
	
	/**
	 * @param lastError
	 *            the lastError to set
	 */
	private void setLastError(long lastError) {

		this.lastError = lastError;
	}
	
	/**
	 * @return
	 */
	public String getErrorString() {

		StringBuilder builder = new StringBuilder();
		for (String error : getErrors()) {
			builder.append(error);
		}
		return builder.toString();
	}
	
	public String getSMSMode() {

		return smsmode;
	}
	
	/**
	 * 
	 * @author Christian
	 * @param arg0
	 * @return
	 * @see java.lang.Comparable#compareTo(java.lang.Object)
	 */
	@Override
	public int compareTo(SMSAlamierung arg0) {
		
		if(nummer.equals(arg0.getNummer())) {
			if(smsmode.equals("direct")) {
				return 1;
			}
			if(smsmode.equals("gold")) {
				return 0;
			}
			if(smsmode.equals("basic")) {
				return -1;
			}
		}
		return nummer.compareTo(arg0.getNummer());
	}

	/**
	 * @return
	 */
	public String getUserId() {

		return userid;
	}

	public String getAbsender() {
		return absender;
	}

	public void setAbsender(String absender) {
		this.absender = absender;
	}

	
	/**
	 * @return the kontostand
	 */
	public String getKontostand() {
	
		return kontostand;
	}

	
	/**
	 * @param kontostand the kontostand to set
	 */
	public void setKontostand(String kontostand) {
	
		this.kontostand = kontostand;
	}
}
